import axios from "@/utils/request";
// 重新导入axios
import request from "axios";
// 导入store实例
import store from "@/store";
// 用户登录
export const loginApi = (loginForm) => {
  return axios({
    method: "POST",
    url: "/v1_0/authorizations",
    data: loginForm,
  });
};
// 刷新token
export const refreshTokenApi = () => {
  // 这里用的是axios发请求，而不是request
  // 因为如果用了request发请求了，会触发请求拦截器，会给后台携带一个无效的token
  // 这里需要把refreshToken带给后台
  return request({
    method: "PUT",
    url: "https://toutiao.itheima.net/v1_0/authorizations", //没有配置基地址，所以需要写完整地址
    headers: { Authorization: `Bearer ${store.state.user.refresh_token}` },
  });
};
// 用户基本资料
export const getUserInformationApi = () => {
  return axios({
    method: "GET",
    url: "/v1_0/user",
  });
};
// 用户个人信息
export const getUserMessageApi = () => {
  return axios({
    method: "GET",
    url: "/v1_0/user/profile",
  });
};
// 修改图片
export const unheadshotApi = (photo) => {
  return axios({
    method: "PATCH",
    url: "/v1_0/user/photo",
    data: photo,
  });
};
// 修改用户个人信息
export const unUserNameApi = (userObj) => {
  return axios({
    method: "PATCH",
    url: "/v1_0/user/profile",
    data: userObj,
  });
};
